Constraining Shapes to Device Grids
QuickDraw GX provides the device-grid style attribute (gxDeviceGridStyle
), which allows you to constrain the geometric points of a shape to integer positions after the style, transform, and view modifications have been made.This style attribute constrains the geometric points of a shape to the nearest integer pixel position on the device to which the shape is rendered. Unlike the source-grid style attribute, the device-grid style attribute never drastically affects the position of the shape. However, for shapes that do not have the device-grid attribute set, QuickDraw GX makes minor modifications when drawing contours whose geometric points lie between pixels; you can use the device-grid style attribute to override these modifications, which typically produces better-looking results.
The sample function in Listing 3-4 creates a star-shaped polygon and rotates it 28 degrees, which causes its geometric points to lie between integer positions.
Listing 3-4 Creating a shape with fractional geometric point positions
void ConstrainShapeToDeviceGrid(void) { long starGeometry[] = {1, /* number of contours */ 9, /* number of points */ ff(40), ff(40), ff(50), ff(20), ff(60), ff(40), ff(80), ff(50), ff(60), ff(60), ff(50), ff(80), ff(40), ff(60), ff(20), ff(50), ff(40), ff(40), }; gxShape aStar; aStar = GXNewPolygons((gxPolygons *) starGeometry); GXSetShapeFill(aStar, gxOpenFrameFill); RotateShapeAboutCenter(aStar, ff(28)); GXDrawShape(aStar); GXDisposeShape(aStar); }Because the geometric points of the rotated star do not lie on integer positions, QuickDraw GX does not draw the contours of the star with the most visually appealing lines; instead, it makes minor adjustments to reflect the fractional part of the geometric point coordinates as shown in Figure 3-37.Figure 3-37 Rotated star not constrained to device grid (magnified 200 percent)
If you constrain the star shape to the device grid by adding this line of code to the sample function:
GXSetShapeStyleAttributes(aStar, gxDeviceGridStyle);QuickDraw GX constrains the shape's geometric points to the device grid before choosing the pixels to represent the shape's contours, which creates better-looking lines, as shown in Figure 3-38.Figure 3-38 Rotated star constrained to device grid (magnified 200 percent)
The sample function in this section uses some concepts from other parts of QuickDraw GX. For more information about rotating, mappings, and transforms, see the chapter "Transform Objects" in Inside Macintosh: QuickDraw GX Objects.
For more information about the
gxDeviceGridStyle
style attribute, see "Style Attributes" on page 3-98.